package com.puboot.module.service.impl;

import com.puboot.module.model.LkComicLang;
import com.puboot.module.mapper.LkComicLangMapper;
import com.puboot.module.service.LkComicLangService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;


/**
 * (LkComicLang)表服务实现类
 *
 * @author Leonidax
 * @since 2024-10-13 18:07:43
 */
@Service
@AllArgsConstructor
public class LkComicLangServiceImpl extends ServiceImpl<LkComicLangMapper,LkComicLang> implements LkComicLangService {
    
    private final LkComicLangMapper lkComicLangMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public LkComicLang queryById(Integer id) {
        return lkComicLangMapper.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param lkComicLang 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<LkComicLang> queryByPage(LkComicLang lkComicLang, PageRequest pageRequest) {
        long total = lkComicLangMapper.count(lkComicLang);
        return new PageImpl<>(lkComicLangMapper.queryAllByLimit(lkComicLang, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param lkComicLang 实例对象
     * @return 实例对象
     */
    @Override
    public LkComicLang insert(LkComicLang lkComicLang) {
        this.lkComicLangMapper.save(lkComicLang);
        return lkComicLang;
    }

    /**
     * 修改数据
     *
     * @param lkComicLang 实例对象
     * @return 实例对象
     */
    @Override
    public LkComicLang update(LkComicLang lkComicLang) {
        this.lkComicLangMapper.update(lkComicLang);
        return this.queryById(lkComicLang.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.lkComicLangMapper.deleteById(id) > 0;
    }
}
